package de.nonspectare.utils;

import java.io.File;
import java.io.FileWriter;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;

public class AntInvoker {

	private File buildFile;
	
	public AntInvoker(File buildFile) {
		super();
		this.buildFile = buildFile;
	}
	
	public void testAnt() {

		File buildFile = this.buildFile;
		Project p = new Project();
		p.setProperty("ant.file", buildFile.getAbsolutePath());
		p.init();
		ProjectHelper helper = ProjectHelper.getProjectHelper();
		p.addReference("ant.projectHelper", helper);
		helper.parse(p, buildFile);
		p.executeTarget(p.getDefaultTarget());
	}
	
	public void changeProperty(String propertyName, String value) {
		
		File buildFile = this.buildFile;
		Project project = new Project();
		project.setProperty("ant.file", buildFile.getAbsolutePath());
		project.init();
		ProjectHelper helper = ProjectHelper.getProjectHelper();
		project.addReference("ant.projectHelper", helper);
		helper.parse(project, buildFile);
//		project.executeTarget(project.getDefaultTarget());
		
		project.setProperty(propertyName, value);

		
		
	}
}
